//
//  CTMoreView.m
//  ConstellationTalk_0.1
//
//  Created by riley on 15/6/15.
//  Copyright (c) 2015年 riley chu. All rights reserved.
//

#import "CTMoreView.h"
#import "CTHeader.h"
#import "CTDebugManager.h"
#import "CTAppLanguage.h"
typedef enum {
    CTMoreViewMoveTypeUp = 1,
    CTMoreViewMoveTypeDown
}CTMoreViewMoveType;
@interface CTMoreView()
{
    UIView      *backGroundView;
    UIView      *froeGroundView;
}

@end

@implementation CTMoreView

@synthesize delegate;

- (void)dealloc
{
    [backGroundView removeFromSuperview];
    backGroundView = nil;
    [froeGroundView removeFromSuperview];
    froeGroundView = nil;
    delegate = nil;
    [CTDebugManager showDebugLogInfo:@"dealloc : CTMoreView Is Removed!!!"];
}
- (instancetype)init
{
    self = [super init];
    if (self)
    {
        self.frame = CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, CT_HEADER_SCREEN_HEIGHT);
    }
    return self;
}
- (void) showMoreViewOn:(UIView *)view withMoreViewType:(CTMoreViewType)type
{
    if (view == nil)
    {
        return;
    }
    [view addSubview:self];
    
    backGroundView = [[UIView alloc]initWithFrame:self.frame];
    backGroundView.alpha = 0.8f;
    backGroundView.backgroundColor = [UIColor blackColor];
    [self addSubview:backGroundView];
    
    froeGroundView = [[UIView alloc]initWithFrame:CGRectMake(0, CT_HEADER_SCREEN_HEIGHT, CT_HEADER_SCREEN_WIDTH, 110)];
    [self addSubview:froeGroundView];
    
    //判断View类型
    if (type == CTMoreViewTypeDefault)
    {
        UIButton *delBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        delBtn.frame  = CGRectMake(10, 0, CT_HEADER_SCREEN_WIDTH-20, 45);
        delBtn.backgroundColor = CT_HEADER_WHITE_COLOR;
        delBtn.layer.masksToBounds = YES;
        delBtn.layer.cornerRadius  = 4;
        [delBtn addTarget:self action:@selector(delBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        delBtn.titleLabel.font = [UIFont systemFontOfSize:20];
        [delBtn setTitle:[CTAppLanguage localizedStringForKey:@"moreView_delete_btn_title" withValue:nil withTable:@"Language"] forState:UIControlStateNormal];
        [delBtn setTitleColor:CT_HEADER_GREEN_COLOR forState:UIControlStateNormal];
        [froeGroundView addSubview:delBtn];
    }
    else if (type == CTMoreViewTypeReport)
    {
        UIButton *reportBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        reportBtn.frame  = CGRectMake(10, 0, CT_HEADER_SCREEN_WIDTH-20, 45);
        [reportBtn addTarget:self action:@selector(reportBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        reportBtn.layer.masksToBounds = YES;
        reportBtn.layer.cornerRadius  = 4;
        reportBtn.backgroundColor = CT_HEADER_WHITE_COLOR;
        reportBtn.titleLabel.font = [UIFont systemFontOfSize:20];
        [reportBtn setTitle:[CTAppLanguage localizedStringForKey:@"moreView_report_btn_title" withValue:nil withTable:@"Language"] forState:UIControlStateNormal];
        [reportBtn setTitleColor:CT_HEADER_GREEN_COLOR forState:UIControlStateNormal];
        [froeGroundView addSubview:reportBtn];
    }
    else
    {
        [CTDebugManager showDebugLogInfo:@"CTMoreViewType 类型不匹配 ！！！"];
    }
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    cancelBtn.frame  = CGRectMake(10, 55, CT_HEADER_SCREEN_WIDTH-20, 45);
    cancelBtn.layer.masksToBounds = YES;
    cancelBtn.layer.cornerRadius  = 4;
    [cancelBtn addTarget:self action:@selector(cancelBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    cancelBtn.titleLabel.font = [UIFont systemFontOfSize:20];
    cancelBtn.backgroundColor = CT_HEADER_WHITE_COLOR;
    [cancelBtn setTitle:[CTAppLanguage localizedStringForKey:@"moreView_cancel_btn_title" withValue:nil withTable:@"Language"] forState:UIControlStateNormal];
    [cancelBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [froeGroundView addSubview:cancelBtn];
    
    [self giveUpAction:CTMoreViewMoveTypeUp withInt:110];
}
//取消
-(void) cancelBtnAction:(UIButton *)sender
{
    if ([self.delegate respondsToSelector:@selector(moreViewCanacelBtnAction:)])
    {
        [self.delegate moreViewCanacelBtnAction:self];
    }
    
     [self giveUpAction:CTMoreViewMoveTypeDown withInt:110];
}
//删除
-(void) delBtnAction:(UIButton *)sender
{
    if ([self.delegate respondsToSelector:@selector(moreViewDelBtnAction:)])
    {
        [self.delegate moreViewDelBtnAction:self];
    }
    
    [self giveUpAction:CTMoreViewMoveTypeDown withInt:110];
}
//举报
-(void) reportBtnAction:(UIButton *)sender
{
    if ([self.delegate respondsToSelector:@selector(moreViewreportBtnAction:)])
    {
        [self.delegate moreViewreportBtnAction:self];
    }
    
     [self giveUpAction:CTMoreViewMoveTypeDown withInt:110];
}

-(void)giveUpAction:(CTMoreViewMoveType )type withInt:(int )int_h
{
    
    if (type == CTMoreViewMoveTypeUp)
    {
        [UIView animateWithDuration:0.3f animations:^
         {
             froeGroundView.frame = CGRectMake(0, CT_HEADER_SCREEN_HEIGHT-int_h, CT_HEADER_SCREEN_WIDTH, int_h);
             
         }completion:^(BOOL finished){
         }];
    }
    else
    {
        [UIView animateWithDuration:0.3f animations:^
         {
             froeGroundView.frame = CGRectMake(0, CT_HEADER_SCREEN_HEIGHT, CT_HEADER_SCREEN_WIDTH, int_h);
             
         }completion:^(BOOL finished)
         {
             [self removeShareView];
         }];
    }
    
}

-(void)removeShareView
{
    if ([self.delegate respondsToSelector:@selector(moreViewDidRemoved:)])
    {
        [self.delegate moreViewDidRemoved:self];
    }
    
    [self removeFromSuperview];
}

@end
